/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.jiujiudevice.service;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.boxin.ims.modules.jiujiudevice.dao.JiuInkDao;
import com.boxin.ims.modules.jiujiudevice.entity.JiuInk;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;

/**
 * 颜料配置Service
 * @author sxh
 * @version 2018-10-08
 */
@Component
@Transactional(readOnly = true)
public class JiuInkService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(JiuInkService.class);
	
	@Autowired
	private JiuInkDao jiuInkDao;
	
	public JiuInk get(Long id) {
		return jiuInkDao.findOne(id);
	}
	
	public Page<JiuInk> find(Page<JiuInk> page, JiuInk jiuInk) {
		DetachedCriteria dc = jiuInkDao.createDetachedCriteria();
		if(StringUtils.isNotBlank(jiuInk.getDeviceSn())){
			dc.add(Restrictions.eq("deviceSn", jiuInk.getDeviceSn()));
		}
		dc.addOrder(Order.asc("name"));
		return jiuInkDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(JiuInk jiuInk) {
		jiuInkDao.save(jiuInk);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		jiuInkDao.delete(id);
	}

	/**
	 * 
	 * @function: <p> 判断改路线名称是否存在</p>
	 * @param name
	 * @return
	 */
	public JiuInk getBySnAndName(String deviceSn, Integer name) {
		// TODO Auto-generated method stub
		DetachedCriteria dc = jiuInkDao.createDetachedCriteria();
		dc.add(Restrictions.eq("deviceSn", deviceSn));
		dc.add(Restrictions.eq("name", name));
		return jiuInkDao.find(dc)!=null &&jiuInkDao.find(dc).size()>0 ? jiuInkDao.find(dc).get(0):null ;
	}

/*	*//**
	 * 
	 * @function: <p>查找所有的墨盒配置 </p>
	 * @return
	 *//*
	public List<JiuInk> findAll() {
		// TODO Auto-generated method stub
		DetachedCriteria dc = jiuInkDao.createDetachedCriteria();
		return jiuInkDao.find(dc);
	}*/

	/**
	 * 
	 * @function: <p> 根据sn查询所有的墨盒配置</p>
	 * @param key
	 * @return
	 */
	public List<JiuInk> findBySn(String key) {
		// TODO Auto-generated method stub
		DetachedCriteria dc = jiuInkDao.createDetachedCriteria();
		dc.add(Restrictions.eq("deviceSn", key));
		return jiuInkDao.find(dc);
	}

	
}
